package com.crm.server.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.crm.common.result.AjaxResult;
import com.crm.common.result.R;
import com.crm.server.service.IUserService;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.crm.server.domin.User;

import java.util.List;

/**
 * @Author: Z.lx
 * @Date: 2025/9/2 15:21
 * @Description:
 **/
@RestController
@RequestMapping("/crm/user")
@RequiredArgsConstructor
public class UserController {
    private final IUserService userService;

    
    /**
     * @Description 搜索用户
     * @Param
     * @Date 2025/9/2 15:24
     **/
    @GetMapping("/search")
    public R<List<User>> list(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> list = userService.list();
        return R.ok(list);
    }

    /**
     * @Description 保存用户
     * @Param
     * @Date 2025/9/2 15:24
     **/
    @PostMapping("/save")
    public AjaxResult save(@RequestBody User user) {
        return AjaxResult.success(userService.save(user));
    }

    /**
     * @Description 删除用户
     * @Param
     * @Date 2025/9/2 15:24
     **/
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        return AjaxResult.success(userService.removeById(id));
    }

    /**
     * @Description 修改用户
     * @Param
     * @Date 2025/9/2 15:24
     **/
    @PutMapping("/update")
    public AjaxResult update(@RequestBody User user) {
        return AjaxResult.success(userService.updateById(user));
    }

    /**
     * @Description 根据id获取用户
     * @Param
     * @Date 2025/9/2 15:24
     **/
    @GetMapping("/select/{id}")
    public R<User> get(@PathVariable Integer id) {
        return R.ok(userService.getById(id));
    }
}
